package org.dromara.solonplugins.orika.test1;

import ma.glasnost.orika.MapperFacade;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Get;
import org.noear.solon.annotation.Inject;
import org.noear.solon.annotation.Mapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 测试Controller
 *
 * @author: aoshiguchen
 */
@Mapping("/")
@Controller
public class IndexController {

    @Inject
    private MapperFacade mapperFacade;

    @Get
    @Mapping("/hello")
    public String hello() {
        return "hello aoshiguchen";
    }

    @Get
    @Mapping("/test1")
    public List<Model2> test1() {
        List<Model1> model1List = new ArrayList<>();
        model1List.add(new Model1("张三", 25));
        model1List.add(new Model1("李四", 30));
        List<Model2> model2List = mapperFacade.mapAsList(model1List, Model2.class);
        return model2List;
    }

    public static class Model1 {
        private String name;
        private int age;

        public Model1(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

    public static class Model2 {
        private String name;
        private int age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }
}
